package com.efuture.jdbctemplate;

import com.efuture.druid.DruidUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Date;
import java.util.List;

/**
 * @ClassNAME JdbcTemplateFzBean
 * @Description 使用JdbcTemplate,输出封装bean对象集合
 * @Author zhaoshanshan
 * @Date 2021/9/20 10:08 下午
 * @Version 1.0
 */
public class JdbcTemplateFzBean {

    public static void main(String[] args) {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(DruidUtils.getDataSource());
        String sql = "select * from emp";
        List<EmpData>  empDataList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<EmpData>(EmpData.class));
        for (EmpData empData:empDataList){
            System.out.println(empData);
        }
    }

}
class EmpData{
    private Integer id;
    private String eName;
    private Integer jobId;
    private Integer mgr;
    private Date joinDate;
    private Double salary;
    private Double bonus;
    private Integer deptId;
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String geteName() {
        return eName;
    }

    public void seteName(String eName) {
        this.eName = eName;
    }

    public Integer getJobId() {
        return jobId;
    }

    public void setJobId(Integer jobId) {
        this.jobId = jobId;
    }

    public Integer getMgr() {
        return mgr;
    }

    public void setMgr(Integer mgr) {
        this.mgr = mgr;
    }

    public Date getJoinDate() {
        return joinDate;
    }

    public void setJoinDate(Date joinDate) {
        this.joinDate = joinDate;
    }

    public Double getSalary() {
        return salary;
    }

    public void setSalary(Double salary) {
        this.salary = salary;
    }

    public Double getBonus() {
        return bonus;
    }

    public void setBonus(Double bonus) {
        this.bonus = bonus;
    }

    public Integer getDeptId() {
        return deptId;
    }

    public void setDeptId(Integer deptId) {
        this.deptId = deptId;
    }
    @Override
    public String toString() {
        return "EmpData{" +
                "id=" + id +
                ", eName='" + eName + '\'' +
                ", jobId=" + jobId +
                ", mgr=" + mgr +
                ", joinDate=" + joinDate +
                ", salary=" + salary +
                ", bonus=" + bonus +
                ", deptId=" + deptId +
                '}';
    }
}